package demo;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.ScrollPane;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.border.Border;

public class CompositeLayoutExample {
    
    private JLabel northLabel;
    private JLabel icon;
    private JTextArea mainTextArea;
    private JCheckBox startupTips;
    private JButton nextTipButton;
    private JButton closeButton;
    private JPanel mainPanel;
    private JSeparator separator;
    
    
    public CompositeLayoutExample(){
        BuildUI();
    }
    
    private void BuildUI() {
        mainPanel = new JPanel();
        BorderLayout mainLayout = new BorderLayout();
        mainPanel.setLayout(mainLayout);
        
        //top elements
        JPanel northPanel = new JPanel(new BorderLayout());
        northPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
        northLabel = new JLabel("JDeveloper Productivity Hints");
        icon = new JLabel();
        icon.setIcon(new ImageIcon("fixtures/resources/monodevelop.png"));
        northPanel.add(northLabel, BorderLayout.WEST);
        northPanel.add(icon, BorderLayout.EAST);
        
        //separator
        separator = new JSeparator();
        northPanel.add(separator, BorderLayout.SOUTH);
        
        //textArea
        JPanel textAreaPanel = new JPanel(new FlowLayout());
        mainTextArea = new JTextArea(10, 50);
        mainTextArea.setText("Closing window using the mouse wheel.");
        
        textAreaPanel.add(mainTextArea);
        textAreaPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
        
        //Buttons
        JPanel southPanel = new JPanel(new BorderLayout());
        southPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
        //checkbox
        startupTips = new JCheckBox();
        startupTips.setText("Show Tips At Startup");
        
        JPanel buttonLayout = new JPanel(new BorderLayout());
        buttonLayout.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
        closeButton = new JButton();
        closeButton.setText("Close");
        nextTipButton = new JButton();
        nextTipButton.setText("Next Tip");
        JPanel flowLayout = new JPanel(new FlowLayout());
        flowLayout.add(nextTipButton);
        flowLayout.add(closeButton);
        buttonLayout.add(flowLayout, BorderLayout.EAST);
        
        southPanel.add(startupTips, BorderLayout.WEST);
        southPanel.add(buttonLayout, BorderLayout.SOUTH);
        
        mainPanel.add(northPanel, BorderLayout.NORTH);
        mainPanel.add(textAreaPanel, BorderLayout.CENTER);
        mainPanel.add(southPanel, BorderLayout.SOUTH);
    }

    public static void main(String[] args) {
        //line - JSeparator
        //border = main
        CompositeLayoutExample ex = new CompositeLayoutExample();
        JPanel main = ex.getMainPanel();
        
        JFrame frame = new JFrame();
        frame.add(main);
        frame.setSize(500, 650);
        //fit every component
        frame.pack();
        frame.setTitle("Tip of the day");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        
    }

    public JLabel getNorthLabel() {
        return northLabel;
    }

    public void setNorthLabel(JLabel northLabel) {
        this.northLabel = northLabel;
    }

    public JLabel getIcon() {
        return icon;
    }

    public void setIcon(JLabel icon) {
        this.icon = icon;
    }

    public JTextArea getMainTextArea() {
        return mainTextArea;
    }

    public void setMainTextArea(JTextArea mainTextArea) {
        this.mainTextArea = mainTextArea;
    }

    public JCheckBox getStartupTips() {
        return startupTips;
    }

    public void setStartupTips(JCheckBox startupTips) {
        this.startupTips = startupTips;
    }

    public JButton getNextTipButton() {
        return nextTipButton;
    }

    public void setNextTipButton(JButton nextTipButton) {
        this.nextTipButton = nextTipButton;
    }

    public JButton getCloseButton() {
        return closeButton;
    }

    public void setCloseButton(JButton closeButton) {
        this.closeButton = closeButton;
    }

    public JPanel getMainPanel() {
        return mainPanel;
    }

    public void setMainPanel(JPanel mainPanel) {
        this.mainPanel = mainPanel;
    }

    public JSeparator getSeparator() {
        return separator;
    }

    public void setSeparator(JSeparator separator) {
        this.separator = separator;
    }

}
